#include<iostream>
#include<algorithm>
using namespace std;
const int N = 55;
int arr[N];
int n;
int main()
{
	cin >> n;
	bool flag = 1, flag2 = 0;
	int idx = 0;
	cin >> arr[1];
	int ma = arr[1];
	for (int i = 2; i <= n; i++) {
		cin >> arr[i];
		if (ma > arr[i]) {
			flag = 0;
			if (flag2 == 0) {
				flag2 = 1;
				idx = i;
			}
		}
		ma = arr[i];
	}
	if (flag) {
		cout << 0 << endl;
		return 0;
	}
	flag = 1;
	int ans = 0;
	while (flag) {
		ans++;
		if (idx != n) {
			sort(arr + 1, arr + n);
		}
		else {
			sort(arr + 2, arr + n + 1);
		}
		flag = 0;
		for (int i = 1; i <= n; i++) {
			if (arr[i] < arr[i - 1]) {
				idx = i;
				flag = 1;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}